package com.jyh.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.jyh.service.MenuService;

@Controller
@RequestMapping(value = "/index")
public class IndexController {
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private MenuService menuService;

	/**
	 * 左侧导航
	 * 
	 * @return
	 */
	@RequestMapping("catalogues")
	@ResponseBody
	public String catalogues(HttpServletRequest request,String cid,HttpSession session) {
		logger.info("cid:{}.",cid);
		String catMenu = menuService.getCatalogueFirst(request,Integer.parseInt(cid),session);
		return catMenu;
	}
	
	/**
	 * 左侧导航
	 * 
	 * @return
	 */
	@RequestMapping("catalogue")
	@ResponseBody
	public ModelAndView catalogueTwo(HttpServletRequest request,String cid,HttpSession session) {
		logger.info("cid:{}.",cid);
		String catMenu = menuService.getCatalogueFirst(request,Integer.parseInt(cid),session);
		ModelAndView mav = new ModelAndView("frame/leftTwo");
		mav.addObject("catMenu", catMenu);
		return mav;
	}
	/**
	 * 头导航
	 * 
	 * @return
	 */
	@RequestMapping("navigate")
	@ResponseBody
	public String navigate(HttpServletRequest request,HttpSession session) {
		String catMenu = menuService.getNavigate(request,session);
		return catMenu;
	}
	
	/**
	 * 跳转头页面
	 * 
	 * @param model 模型参数
	 * @return
	 */
	@RequestMapping(value = "/header", method = RequestMethod.GET)
	public String header(Model model) {
		return "frame/header";
	}
	
	/**
	 * 跳转左侧导航
	 * 
	 * @param model 模型参数
	 * @return
	 */
	@RequestMapping(value = "/left", method = RequestMethod.GET)
	public String left(Model model) {
		return "frame/left";
	}

}
